<template>
  <div class="app-container formList">
    <!-- 订单审核对话框 -->

    <el-form ref="form" :model="form" label-width="120px">
      <div>
        <!-- <i class="MmsUiBlockTitle___line___27lhp1-44-1"></i> -->
        <div class="big_title_style" style="font-size: 18px">
          <span>订单信息</span>
        </div>
        <el-divider></el-divider>
        <div>
          <el-row>
            <el-col :span="12">
              <el-form-item label="供应商名称">
                <span>{{ showData.supplierName }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="结算单号">
                <span>{{ showData.settlementNo }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="订单数量">
                <span>{{ showData.orderNumber }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="售后金额">
                <span>{{ showData.serviceAmountTotal }} 元</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="申请金额">
                <span>{{ showData.settlementMoney }} 元</span>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        <div style="margin-left: 50px">
          <template>
            <el-table
              border
              :data="tableData"
              height="400"
              :summary-method="getSummaries"
              show-summary
              style="width: 100%; margin-top: 20px">
              <el-table-column
                prop="orderNo"
                label="订单编号"
                width="150">
              </el-table-column>
              <el-table-column
                prop="proName"
                label="商品名称"
                width="150">
              </el-table-column>
              <el-table-column
                prop="skuDesc"
                label="商品描述"
                width="140">
              </el-table-column>
              <el-table-column
                prop="costPrice"
                label="供应价格（元）"
                width="120">
              </el-table-column>
              <el-table-column
                prop="itemNumber"
                label="销售数量"
                width="100">
              </el-table-column>
              <el-table-column
                prop="serviceNumber"
                label="售后数量"
                width="100">
              </el-table-column>
              <el-table-column
                prop="serviceAmount"
                label="售后金额（元）"
                width="120">
              </el-table-column>
              <el-table-column
                prop="settlementAmount"
                label="结算金额（元）"
                width="120">
              </el-table-column>
              <el-table-column
                prop="payTime"
                label="下单时间"
                width="170">
              </el-table-column>
            </el-table>
          </template>
        </div>
      </div>
      <div style="margin-top: 60px">
        <!-- <i class="MmsUiBlockTitle___line___27lhp1-44-1"></i> -->
        <div class="big_title_style" style="font-size: 18px">
          <span>审核信息</span>
        </div>
        <el-divider></el-divider>
        <div>
          <el-row>
            <el-col :span="12">
              <el-form-item label="申请时间">
                <span>{{ showData.applyAuthTime }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="申请人账号">
                <span>{{ showData.createName }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="审核时间">
                <span>{{ showData.auditTime }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="审核人账号">
                <span>{{ showData.auditName }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="更新时间">
                <span>{{ showData.updateTime }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="更新人账号">
                <span>{{ showData.updateName }}</span>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="审核意见">
                <span>{{ showData.auditMsg }}</span>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </div>
    </el-form>

  </div>
</template>

<script>
  import {
    getSettlementDetailById
  } from '@/api/supplier/settlement'

  export default {
    name: 'Settlement',
    components: {},
    data() {
      return {
        title: "订单审核",
        form: {
          auditStatus: "1"
        },
        //订单详细数据
        tableData: [],
        //自动撑开表格
        fit: true,

        //订单数据
        showData: []
      }
    },
    props: {
      //是否显示
      viewOpen: {
        type: Boolean,
        default: false,
      },
      auditSettlementIdStr: {
        type: Number,
        default: null,
      }
    },
    created() {
      if (this.auditSettlementIdStr) {
        this.getOrderDetailById(this.auditSettlementIdStr)

      }
    },
    methods: {
      getSummaries(param) {
        const {columns, data} = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '总价';
            return;
          }
          const values = data.map(item => Number(item[column.property]));
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
            sums[index];
          } else {
            sums[index] = 'N/A';
          }
        });

        return sums;
      },

      /** 提交操作 */
      cancel() {
      },

      //查询订单详细
      getOrderDetailById(row) {
        getSettlementDetailById(row).then(response => {
          this.tableData = response.orderSettlementVos;
          this.showData = response;
        })
      },

      //关闭弹框事件
      handleClose(done) {
        this.$emit("update:viewOpen", false);
      }
    }
  }
</script>
<style scoped>
  .MmsUiBlockTitle___line___27lhp1-44-1 {
    display: inline-block;
    background: #407cff;
    width: 2px;
    height: 16px;
    margin-right: 8px;
  }

  .MmsUiBlockTitle___title___2C-H-1-44-1 {
    display: inline-block;
    font-size: 20px;
    color: #333;
    position: relative;
  }

  .el-table {
    overflow: visible !important;
  }
</style>
